"""
FileName：logger.py
Description：
Author：gaojiahui
Time：2025/8/18 20:10
Website：https://gitee.com/gao-jiahui
"""
import logging

from config.settings import settings


def setup_logger():
    """配置项目日志"""
    logger = logging.getLogger("PIG_API_TEST")
    logger.setLevel(logging.DEBUG)

    # 文件处理器
    log_file = settings.LOG_DIR / "pig_test.log"
    file_handler = logging.FileHandler(log_file, encoding='utf-8')
    file_handler.setLevel(logging.DEBUG)

    # 控制台处理器
    console_handler = logging.StreamHandler()
    console_handler.setLevel(logging.INFO)

    # 格式化
    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(module)s:%(lineno)d - %(message)s'
    )
    file_handler.setFormatter(formatter)
    console_handler.setFormatter(formatter)

    logger.addHandler(file_handler)
    logger.addHandler(console_handler)
    return logger

logger = setup_logger()